const path = require("path")
const webpack = require('webpack')
const coverVant = path.resolve(__dirname, 'src/styles/coverVant.less')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']

const plugins = [
  new CompressionWebpackPlugin({
    algorithm: 'gzip',
    test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
    threshold: 10240,
    minRatio: 0.8
  }),
  new webpack.optimize.LimitChunkCountPlugin({
    maxChunks: 5,
    minChunkSize: 100
  }),
]

module.exports = {
  publicPath: './',
  devServer: {
    port: 9527,
    hot: true,
    open: true,
    proxy: {
      '/categoryApi': {
        target: 'http://cdn.apc.360.cn/index.php',
        changeOrigin: true,
        pathRewrite: {
          '^/categoryApi': ''
        }
      },
      '/detailApi': {
        target: 'http://wallpaper.apc.360.cn/index.php',
        changeOrigin: true,
        pathRewrite: {
          '^/detailApi': ''
        }
      },
      '/hotApi': {
        target: 'http://openbox.mobilem.360.cn/html/api/wallpaperhot.html',
        changeOrigin: true,
        pathRewrite: {
          '^/hotApi': ''
        }
      },
    }
  },
  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          hack: `true; @import "${coverVant}";`
        }
      }
    }
  },
  configureWebpack: {
    plugins
  }
}
